import { RequestApi } from '../service/requestApi'

export class Dict {
  static dict = new Map()

  static getDict(key) {
    return this.dict.get(key)
  }

  static setDict(key, value) {
    this.dict.set(key, value)
    return this.dict.get(key)
  }

  static async hadDict() {
    if (this.dict.size === 0) {
      let { data } = await RequestApi.getDict()
      data.forEach(item => {
        this.setDict(item.dictType, item.dictDataList)
      })
    }
  }
}

export class Filter extends Dict {
  constructor() {
    super()
  }

  static dictFilter(value, key) {
    const list = this.getDict(key)
    if (list?.length) {
      const data = list.find(item => item.label == value)
      return data.value || '类型错误'
    } else {
      return '类型错误'
    }
  }
}

